package com.cty.controller;


import com.cty.pojo.Customer;
import com.cty.pojo.Praise;

import com.cty.service.RedisLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class PraiseController {

    @Autowired
    private RedisLikeService redisLikeService;

    //点赞
    @PostMapping("/praise/save")
    public String save2redis(Praise praise,Integer  praiseCount , HttpSession session){
        System.out.println("点赞接收到的praise:" + praise);
        System.out.println("点赞后，总点赞数：" +praiseCount );
        Customer customer =(Customer) session.getAttribute("loginCustomer");
        Integer custId = customer.getCusId();
        System.out.println("当前登录的用户id:" + custId);
        praise.setCusId(custId);


        redisLikeService.saveLike2Redis(praise,praiseCount); // redis --- mysql

        return "save praise success";
    }

   //取消点赞
   @PostMapping("/praise/cancle")
   public String cancle2redis(Praise praise, Integer  praiseCount , HttpSession session){
       System.out.println("取消点赞接收到的praise:" + praise);
       System.out.println("取消点赞后，总点赞数：" +praiseCount );
       Customer customer =(Customer) session.getAttribute("loginCustomer");
       Integer custId = customer.getCusId();
       System.out.println("当前登录的用户id:" + custId);
       praise.setCusId(custId);


       redisLikeService.cancleLike2Redis(praise,praiseCount);
       return "cancel praisesuccess";
   }

}
